package BS_74;

public class Solution {
	public boolean searchMatrix(int[][] matrix, int target) {
		int m = matrix.length;
		if (m == 0) {
			return false;
		}
		int n =matrix[0].length;
		int left =0,right=n*m-1;
		int pivotX,privtEle;
		while (left<=right) {
			pivotX=(left+right)/2;
			privtEle=matrix[pivotX/n][pivotX%n];
			if (target==privtEle) {
				return true;
			}else {
				if (target<privtEle) {
					right=pivotX-1;
				}else {
					left =pivotX+1; 
				}
			}
		}
		return false;
		
		
		
	}
}
